package JUC并发编程.三大特性.原子性.CAS保证原子性;

import java.util.concurrent.atomic.AtomicStampedReference;

public  class CASTest2 {

    // stamp: 邮票，印记   reference:参考，提到
    public static void main(String[] args) {
        AtomicStampedReference<String> reference = new AtomicStampedReference<>("AAA",1);

        String oldValue = reference.getReference();
        int oldVersion = reference.getStamp();

        boolean one = reference.compareAndSet(oldValue, "B", oldVersion, oldVersion +1);
        System.out.println("修改版本 1 = " + one);

        boolean two = reference.compareAndSet(oldValue, "C", oldVersion, 3);
        System.out.println("修改版本2 = " + two);


    }


}
